<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php
class UserEvent extends CMiniyunModel {
    public static function model($className = __CLASS__) {
        return parent::model ( $className );
    }
    
    public function tableName() {
        return Yii::app ()->params ['tablePrefix'] . 'events';
    }
    
    
    public function CreateEvent($user_id, $user_device_id, $action, $path, $context, $event_uuid) {
        $this->setAttribute ( "user_id", $user_id );
        $this->setAttribute ( "user_device_id", $user_device_id );
        $this->setAttribute ( "action", $action );
        $this->setAttribute ( "file_path", $path );
        $this->setAttribute ( "context", $context );
        $this->setAttribute ( "event_uuid", $event_uuid );
        $this->save ();
    }
    
    
    public static function batchCreateEvents($user_id, $user_device_id, $files) {
        foreach ( $files as $file ) {
            $event = new UserEvent ();
            $event->setAttribute ( "user_id", $user_id );
            $event->setAttribute ( "user_device_id", $user_device_id );
            $event->setAttribute ( "action", $file->action );
            $event->setAttribute ( "path", $file->from_path );
            $event->setAttribute ( "context", $file->context );
            $event->setAttribute ( "event_uuid", $file->event_uuid );
            $event->save();
        }
    }
}
?>